﻿<%@ Page Title="" Language="C#" MasterPageFile="../Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcWeb.Models.Sys_SoftAuthKey>" %>

<%@ Import Namespace="MvcWeb.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    新增授权
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="server">
    <script src="../../Scripts/jquery.ajaxfileupload.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#cancel").click(function () {
                window.location = "/Auth/index";
            });

            $("#submit").click(function () {
                var WPlace = $("#WPlace").val();
                if (WPlace == "") {
                    $.messager.alert("提示信息", "软件授权属地不能为空", "info");
                    return false;
                }

                var SoftNo = $("#SoftNo").val();
                if (SoftNo == "") {
                    $.messager.alert("提示信息", "软件标识不能为空", "info");
                    return false;
                }

                return true;
            });
        });


        $(function () {
            $('#fileToUpload').change(function () {
                ajaxFileUpload();
            });
        });

        function ajaxFileUpload() {
            $("#loading")
                .ajaxStart(function () {
                    $(this).show();
                })
                .ajaxComplete(function () {
                    $(this).hide();
                });
            $('input:file').each(function () {
                $.ajaxFileUpload({
                    url: '/Auth/UploadMatch',
                    secureuri: false,
                    fileElementId: $(this).attr('id'),
                    dataType: 'json',
                    success: function (data) {
                        ShowData(data);
                    },
                    error: function (data) {
                        ShowData(data);
                    }
                });
            });

            $('#fileToUpload2').change(function () {
                if ($("#fileToUpload1").val() == "") {
                    alert("请选择机器码文件");
                    return;
                }
                if ($("#fileToUpload2").val() == "") {
                    alert("请选择许可文件");
                    return;
                }
                ajaxFileUpload();

            });
        }





        function ShowData(data) {
            if (data.status == "error") {
                $("#status").html("验证失败：" + data.msg);
                $("#SoftNo").val("");
                $("#SoftVersion").val("");
                $("#MachineCode").text("");
                $("#CPUID").val("");
                $("#MAC").val("");
                $("#MCodeFileH").attr("href", "javascript:void(0)");
                $("#MCodeFile").val("");
                $("#SkeyFile").val("");
                $("#SoftCName").html("");
                $("#SoftID").val("");
            }
            else {
                $("#status").html(data.msg);
                $("#SoftNo").val(data.ProductId);
                $("#SoftVersion").val(data.Version);
                $("#MachineCode").text(data.MachinCode);
                $("#CPUID").val(data.CPUID);
                $("#MAC").val(data.MAC);
                $("#MCodeFileH").attr("href", data.McodeFile);
                $("#MCodeFile").val(data.McodeFile);
                $("#SkeyFile").val(data.SkeyFile);
                $("#SoftCName").html(data.SOFTCNAME);
                $("#SoftID").val(data.SoftID);
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="TabTitle" runat="server">
    新增软件授权
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="main_zone">
        <table width="99%" style="text-align: left;" border="0" align="center" cellpadding="3"
            cellspacing="1">
            <tr>
                <td width="18%" class="left_title_1">
                    请选择机器码文件
                </td>
                <td width="32%" colspan="3">
                    <input id="fileToUpload1" type="file" name="fileToUpload" style="width: 200px; height: 25px;" />
                </td>
            </tr>
            <tr>
                <td width="18%" class="left_title_1">
                    请选择许可文件
                </td>
                <td width="32%" colspan="3">
                    <input id="fileToUpload2" type="file" name="MfileToUpload" style="width: 200px; height: 25px;" />&nbsp;&nbsp;&nbsp;<span
                        id="Span1" style="color: Red;"></span>
                    <img id="loading" src="/Content/images/loading.gif" style="display: none; height: 25px;
                        width: 25px;" />
                </td>
            </tr>
            <tr>
                <td width="18%" class="left_title_2">
                    软件名称
                </td>
                <td width="32%">
                    <span id="SoftCName"></span>
                    <%= Html.HiddenFor(mod => mod.SoftID, new { @readonly = "readonly" })%>
                </td>
                <td width="18%" class="left_title_2">
                    软件标识编号
                </td>
                <td width="32%">
                    <%= Html.TextBoxFor(mod => mod.SoftNo,new { @readonly = "readonly" })%>
                </td>
            </tr>
            <tr>
                <td class="left_title_1">
                    机器码
                </td>
                <td colspan="3">
                    <%= Html.TextAreaFor(mod => mod.MachineCode, new { style = "height:50px;width:750px;readonly:expression(this.readOnly=true);" })%>
                </td>
            </tr>
            <tr>
                <td class="left_title_2">
                    授权属地
                </td>
                <td>
                    <%= Html.TextBoxFor(mod => mod.WPlace)%>
                </td>
                <td class="left_title_2">
                    软件版本
                </td>
                <td>
                    <%= Html.TextBoxFor(mod => mod.SoftVersion, new { @readonly = "readonly" })%>
                </td>
            </tr>
            <tr>
                <td class="left_title_1">
                    CPUID
                </td>
                <td>
                    <%= Html.TextBoxFor(mod => mod.CPUID, new { style = "width:350px;readonly:true;" })%>
                </td>
                <td class="left_title_1">
                    MAC
                </td>
                <td>
                    <%= Html.TextBoxFor(mod => mod.MAC, new { @readonly = "readonly" })%>
                </td>
            </tr>
            <tr>
                <td class="left_title_2">
                    机器码文件
                </td>
                <td>
                    <%= Html.HiddenFor(mod => mod.MCodeFile, new { @readonly = "readonly" })%>
                    <a href="javascript:void(0)" id="MCodeFileH" hidefocus="true" target="_blank">
                        <img src="../../Content/images/lock.png" style="height: 21px; cursor: pointer; width: 25px"
                            border="0" />
                    </a>
                </td>
                <td class="left_title_2">
                    许可文件
                </td>
                <td>
                    <%= Html.HiddenFor(mod => mod.SKeyFile, new { @readonly = "readonly" })%>
                    <img src="../../Content/images/keyU.png" style="height: 21px; cursor: pointer; width: 25px"
                        border="0" />
                    <span>保存后生成Key文件</span>
                </td>
            </tr>
            <tr>
                <td class="left_title_1">
                    授权人
                </td>
                <td>
                    <%= Html.TextBoxFor(mod => mod.Creator, new { @readonly = "readonly",Value = (Session["user"] as Sys_User).UserCName })%>
                </td>
                <td class="left_title_1">
                    授权时间
                </td>
                <td>
                    <%= Html.TextBoxFor(mod => mod.CreateDate, new { @readonly = "readonly",Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss")  })%>
                </td>
            </tr>
            <tr>
                <td colspan="4" class="left_title_2" style="text-align: center;">
                    <input id="submit" type="submit" value="保存" />
                    <input id="cancel" type="button" value="取消" />
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
